//
//  Dog.m
//  <8>Archiving
//
//  Created by chen on 16/9/8.
//  Copyright © 2016年 tyrad. All rights reserved.
//

#import "Dog.h"

@implementation Dog

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        _name = @"小Y";
        _age = 100;
        _weight = 80 ;
        _isAlive = YES ; 
        
    }
    return self;
}

//归档
- (void)encodeWithCoder:(NSCoder *)aCoder{

    [aCoder encodeObject:_name forKey:@"name"];
    
    [aCoder encodeInteger:_age forKey:@"age"];
    
    [aCoder encodeDouble:_weight forKey:@"weight"];
    
    [aCoder encodeBool:_isAlive forKey:@"isAlive"];

}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super init]; //因为本身继承自NSObject 所以[super init]
    if (self) {
        _name  =  [coder decodeObjectForKey:@"name"];
        _age   = [coder decodeIntegerForKey:@"age"];
        _weight = [coder decodeDoubleForKey:@"weight"];
        _isAlive = [coder decodeBoolForKey:@"isAlive"];
    }
    return self;
}

@end












